﻿@model WoBian.Models.Admin.User.AdminUserModel
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>创建账户</title>
    <script type="text/javascript">
        function isnull(str) {
            if (str.length == 0) {
                return true;
            }
            else {
                return false;
            }
        }
        function isequal(str1,str2){
            if(str1==str2){
                return true;
            }
            else{
                return false;
            }
        }

        //检查email邮箱
        function isemail(str) {
            var reg = /^([a-zA-Z0-9_-])+@Html.Encode("@")+([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
            return reg.test(str);
        }

        function Check() {
            var Name = document.getElementById("Name").value;
            var Password=document.getElementById("Password").value;
            var Password2 = document.getElementById("Password2").value;
            var TrueName = document.getElementById("TrueName").value;
            var Age = document.getElementById("Age").value;
            var Address=document.getElementById("Address").value;
            var EMailAddress=document.getElementById("EMailAddress").value;
            var IdNumber = document.getElementById("IdNumber").value;
            var IsLock = document.getElementById("IsLock").value;
            var MobilePhone = document.getElementById("MobilePhone").value;
            var NickName = document.getElementById("NickName").value;

            var Remark = document.getElementById("Remark").value;
            var msg = "";
            if (isnull(Name)) {//空用户名验证
                msg += "用户名不能为空!";
            }
            else if (isnull(Password)) {//空密码验证
                msg += "密码不能为空！";
            }
            else if(isnull(Password2)){//空重复密码验证
                msg +="请再次输入密码！";
            }
            else if(isnull(Password2)==false){//两次密码是否相同验证
                if(isequal(Password,Password2)==false){
                    msg +="两次输入密码不相同，请重新输入！";
                }
            }
            else if(isnull(EMailAddress)){//空邮箱验证
                msg += "请输入邮箱地址！";
            }
            else if(isnull(EMailAddress)==false){//邮箱地址是否规范验证
                if (isemail(EMailAddress) == false) {
                    msg +="请输入正确的邮箱地址！";
                }
            }

            if(msg!="")
            {
            alert(msg);
            return false;
            }
    }
        function Right(){
            if(Check()==false){
                return false
            }
            else{
                return true;
            }
        }
     </script>

</head>
<body ondrop="return false">
    @using (Html.BeginForm("Create", WoBian.Lib.ConstString.MapRouteControllers.AdminUser, FormMethod.Post, new { id = "MyForm", name = "MyForm", enctype = "multipart/form-data" }))
    {
        <fieldset>
            <legend>用户创建页</legend>
            <div>
                 @Html.HiddenFor(m => m.UserId)</div>
            <div>
                用户ID:&nbsp @Html.TextBoxFor(m => m.Name)</div>
            <div>
                密码:&nbsp&nbsp&nbsp @Html.PasswordFor(m=>m.Password)</div>
            <div>
                重复密码:<input type="password" id="Password2" name="Password2" /></div>
            <div>
                真实姓名:@Html.TextBoxFor(m => m.TrueName)</div>
            <div>
                年龄:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.Age)</div>
            <div>
                地址:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.Address)</div>
            <div>
                邮箱:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.EMailAddress)</div>
            <div>
                身份证号:@Html.TextBoxFor(m => m.IdNumber)</div>
            <div>
                是否锁定: @Html.RadioButtonFor(m => m.IsLock, "Y")是
                          @Html.RadioButtonFor(m => m.IsLock, "N")否</div>
            <div>
                电话:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.MobilePhone)</div>
            <div>
                昵称:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.NickName)</div>
            <div>
                头像: 
                <div draggable="true" id="MyDrag" style="width: 100px; height: 100px; border: 1px solid #000000">
                </div>
                <input type="file" id="myFile" name="myFile" />
            </div>
            <div>
                备注:&nbsp&nbsp&nbsp @Html.TextBoxFor(m => m.Remark)</div>
            <p>
                <input type="submit" value="保存" />
                <input type="reset" value="重置" />
            </p>
            
        </fieldset>
    }
    <div>
        @Html.ActionLink("返回主页", "Index")
    </div>
</body>
</html>
<script type="text/javascript">
    window.onload = function () {
        var MyDrag = document.getElementById("MyDrag");
        var MyFile = document.getElementById("myFile");
        var MyFile1 = document.getElementById("myFile1");
        // 判断是否图片
        function isImage(type) {
            switch (type) {
                case 'image/jpeg':
                case 'image/png':
                case 'image/gif':
                case 'image/bmp':
                case 'image/jpg':
                    return true;
                default:
                    return false;
            }
        }
        MyDrag.ondrop = function (e) {
            var file = e.dataTransfer.files[0];
            MyFile.files[0] = file;
            var filereader = new FileReader();
            if (isImage(file.type)) {
                filereader.onload = (function (thefile) {
                    return function (e) {
                        MyDrag.innerHTML = "<img src='" + e.target.result + "' style='width:100px; height:100px;'/>";
                    }
                })(file)
                filereader.readAsDataURL(file);
            }
            else {
                alert("请使用jpeg、png、gif、bmp、jpg格式的图片！");
                return false;
            }
        }
        MyFile.onchange = function (e) {
            var file = MyFile.files[0];
            var isImg = isImage(file.type);
            if (isImg) {
                var filereader = new FileReader();
                filereader.onload = (function (thefile) {
                    return function (e) {
                        MyDrag.innerHTML = "<img src='" + e.target.result + "' style='width:100px; height:100px;'/>";
                    }
                })(file)
                filereader.readAsDataURL(file);
            }
            else {
                alert("请使用jpeg、png、gif、bmp、jpg格式的图片！");
                return false;
            }
        }
    }

        

    </script>
